using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using MySql.Data.MySqlClient;

//myDateTime.ToString("yyyy:MM:dd hh:mm:ss") 

namespace iri10
{
    public class BaseDatos
    {
        static MySqlConnection conexion;

        public static void Inicializar()
        {
            conexion = new MySqlConnection("Server=localhost;Port=3306;Database='pds';User ID='root';Password='root';");
            conexion.Open();
        }
        public static object[] Consultar(string consulta)
        {
            object[] o;
            ArrayList l = new ArrayList();
            MySqlCommand comm = new MySqlCommand(consulta, conexion);
            MySqlDataReader rd = null;

            try
            {
                rd = comm.ExecuteReader();
                o = new object[rd.FieldCount];
                while (rd.Read())
                {
                    object[] v = new object[rd.FieldCount];
                    rd.GetValues(o);
                    o.CopyTo(v, 0);
                    l.Add(v);
                }
            }
            finally
            {
                if (rd != null)
                    rd.Close();
            }
            return l.ToArray();
        }
        public static object ConsultarSimple(string consulta)
        {
            MySqlCommand comm = new MySqlCommand(consulta, conexion);
            return comm.ExecuteScalar();
        }
        public static int Ejecutar(string comando)
        {
            MySqlCommand comm = new MySqlCommand(comando, conexion);
            return comm.ExecuteNonQuery();
        }
    }

}